package com.zqh.apiordersubmit.controller;


import com.zqh.apiordersubmit.redis.RedisUtil;
import com.zqh.apiordersubmit.service.OrderSubmitService;
import com.zqh.myfmmall.clients.MqMessageClient;
import com.zqh.myfmmall.clients.WechatPayClient;
import com.zqh.myfmmall.result.Result;
import com.zqh.myfmmall.result.ResultType;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("order")
@Slf4j
public class OrderSubmitController{
    @Autowired
    private HttpServletRequest request;
    @Resource
    private OrderSubmitService orderSubmitService;
    @Autowired
    private RedisUtil redisUtil;
    @Autowired
    private WechatPayClient wechatPayClient;
    @Autowired
    private MqMessageClient mqMessageClient;


    @PostMapping("submit")
    public Result submit(@RequestBody ArrayList<String> shoppingCartIds, @RequestParam("addrId") String addrId) {
        String token = request.getHeader("token");
        String userId = (String) redisUtil.get(token);
        Map<String, String> orderInfoMap = new HashMap<>();
        return orderSubmitService.submitOrder(shoppingCartIds,addrId,userId);
    }
}

